package com.hl.card.credit.creditcard;

import com.hl.card.credit.domain.CreditCardOrder;
import com.hl.card.credit.domain.InitailFormDTO;
import com.hl.card.credit.service.CreditCardOrderService;
import com.hl.card.credit.utill.HttpClientTool;
import com.hl.card.credit.utill.PingAnTool;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.io.IOException;
import java.util.*;

import static com.hl.card.credit.utill.PingAnTool.getUrlReal;
import static com.hl.card.credit.utill.StatusTool.getSign4;


/**
 * 信用卡项目对接平安正式环境
 */
@RunWith(SpringRunner.class)
@SpringBootTest
public class CreditCardReal {

    private static String  order_id="m180320106300000201804191255555271111";

    @Autowired
    private CreditCardOrderService creditCardOrderService;


    @Test
    public void realRequest() {
        String url="";
        String seqId= PingAnTool.getSeqId();
        System.out.println("生成的订单号："+seqId);
        CreditCardOrder creditCardOrder=new CreditCardOrder();
        creditCardOrder.setOrderCode(seqId);
        creditCardOrder.setOrderid(seqId);
        creditCardOrder.setCurrentstatus("测试平安接口");
//        creditCardOrderService.save(creditCardOrder);
        InitailFormDTO initDTO=new InitailFormDTO();
        /***************************参数赋值，请和业务确定*********************************************/
        initDTO.setPartnerSeqId(seqId);
        initDTO.setScc(PingAnTool.scc);
//        initDTO.setTemplateNo("s180419Oot");
        initDTO.setMt("123456789");
        initDTO.setCcp("1a2a3a9");
        initDTO.setVersionNo("R10310");
        initDTO.setOnlineSQFlag("N");
        initDTO.setCardCatenaNo("01a02a04");
        initDTO.setChannel("WXHZF");
        /***************************中文记得转码UTF-8*************************************************/
        System.out.println("需要加密的入参:"+initDTO);
        url=getUrlReal(initDTO);
        System.out.println( "最终生成测试环境url：" + url);
    }

    /**
     * post 方式得到申请链接
     *
     */
    @Test
    public void realRequestPost() {
        String url="";
        String seqId=PingAnTool.getSeqId();
        System.out.println("生成的订单号："+seqId);
        InitailFormDTO initDTO=new InitailFormDTO();
        Map param=new TreeMap();
        param.put("versionNo","R10310");
        param.put("scc","235180089");
        param.put("onlineSQFlag","N");
        param.put("channel","WXHZF");
        try {
            String req= HttpClientTool.doPost("https://c.pingan.com/ca/applyIndex",param);
        } catch (IOException e) {
            e.printStackTrace();
        }
        url=getUrlReal(initDTO);
        System.out.println( "最终生成测试环境url：" + url);
    }
    /**
     * 自己的状态查询
     *
     */
    @Test
    public void queryStatus() {
        String curl = "https://c.pingan.com/ca/scc/merchant/order/getStatus";
        Map<String,String[]> map = new TreeMap();
        map.put("merchant_key",new String[]{"6e2b234cc91032a2355389bfa7266be2"});
        map.put("order_id", new String[]{"m180409543500000201811130253306248603"});
        map.put("timestamp",new String[]{System.currentTimeMillis()+""});
        String sign=getSign4(map);
        Map param=new HashMap();
        param.put("order_id",map.get("order_id")[0]);
        param.put("timestamp",map.get("timestamp")[0]);
        param.put("sign",sign);
        HttpClientTool.createSSLClientDefault();
        String res=HttpClientTool.doGetSSL(curl,param);
        System.out.println(res);
    }

    @Test
public  void testDate(){

    String str=PingAnTool.getSeqId();


        System.out.println(str);


}





    }
